import {
  saveFormIdRequest,
  sendMessageRequest
} from '../service/message-push-controller'
import { imFormatTime } from './lodashmin/formatDate'

const messagePush = {
  insertFormId: ({ formId, openId, userId }) => {
    if (formId == 'the formId is a mock one') {
      // 模拟器的formid 忽略
    } else {
      if (openId && formId && userId) {
        saveFormIdRequest({ formId, openId, userId }).then(({ data }) => {})
      }
    }
  },
  sendMessage: ({ name, userId, templateType, content, role = '' }) => {
    let date = imFormatTime(new Date())

    let parmas = {
      sendModel: {
        page: `pages/message-list/index?role=${role || ''}&message=1`,
        data: {
          keyword1: {
            value: name
          },
          keyword2: {
            value: date
          },
          keyword3: {
            value: content
          }
        }
      },
      templateType,
      userId
    }

    sendMessageRequest(parmas)
  }
}
export default messagePush
